<?php defined('SYSPATH') OR die('No direct access allowed.');

class sigi_Core {
	public static function actionbox_small($controller, $id,$form='input'){
		$r='<div class="actionbox">
		<ul class="nav">
			<li>
				'.html::image(IMGPATH.'edit_menu.png').'
				<ul>
					<li>'.html::anchor('ext/'.$controller.'/form/'.$form.'/'.$id,  html::image(IMGPATH.'edit.png')).'</li>
					<li>'.html::anchor('ext/'.$controller.'/action/delete/'.$id,  html::image(IMGPATH.'delete.png'),  array('class'=>'confirm')).'</li>				
				</ul>
			</li>
		</ul>
		</div>';
		return $r;
	}
	
	public static function actionbox($controller, $id, $form='input'){
		$r='<div class="actionbox">
		<ul class="nav">
			<li>
				'.html::image(IMGPATH.'edit_menu.png').'
				<ul>
					<li>'.html::anchor('ext/'.$controller.'/form/'.$form.'/'.$id,  html::image(IMGPATH.'edit.png')).'</li>
					<li>'.html::anchor('ext/'.$controller.'/action/up/'.$id, html::image(IMGPATH.'up.png')).'</li>
					<li>'.html::anchor('ext/'.$controller.'/action/down/'.$id, html::image(IMGPATH.'down.png')).'</li>
					<li>'.html::anchor('ext/'.$controller.'/action/delete/'.$id,  html::image(IMGPATH.'delete.png'),  array('class'=>'confirm')).'</li>
					
				</ul>
			</li>
		</ul>
		</div>';
		return $r;
	}
	
	
	public static function actionbox_clear($controller, $id, $param){
		$r='<div class="actionbox">
		<ul class="nav">
			<li>
				'.html::image(IMGPATH.'edit_menu.png').'
				<ul>
					<li>'.html::anchor('ext/'.$controller.'/action/empty/'.$id.'/'.$param,  html::image(IMGPATH.'clear.png'),  array('class'=>'confirm')).'</li>				
				</ul>
			</li>
		</ul>
		</div>';
		return $r;
	}
	
	
	public static function actionbox_params($controller, $id, $params){
		$r='<div class="actionbox">
		<ul class="nav">
			<li>
				'.html::image(IMGPATH.'edit_menu.png').'
				<ul>
				';
				foreach($params as $param=>$paramvals){
					
					switch($param){
						case 'EDIT':
						$r.='<li>'.html::anchor('ext/'.$controller.'/form/'.$paramvals.'/'.$id,  html::image(IMGPATH.'edit.png')).'</li>';
						break;
						case 'UP':
						$r.='<li>'.html::anchor('ext/'.$controller.'/action/up/'.$id, html::image(IMGPATH.'up.png')).'</li>';
						break;
						case 'DOWN':
						$r.= '<li>'.html::anchor('ext/'.$controller.'/action/down/'.$id, html::image(IMGPATH.'down.png')).'</li>';
						break;
						case 'DEL':
						$r.= '<li>'.html::anchor('ext/'.$controller.'/action/delete/'.$id,  html::image(IMGPATH.'delete.png'),  array('class'=>'confirm')).'</li>';
						break;
						case 'EMPTY':
						$r.= '<li>'.html::anchor('ext/'.$controller.'/action/empty/'.$id.'/'.$paramvals,  html::image(IMGPATH.'clear.png'),  array('class'=>'confirm')).'</li>';
						break;
					}
				}
				$r.= '
				</ul>
			</li>
		</ul>
		</div>';
		return $r;
	}
	
	public static function addbox($params, $style='actionbox'){
	$r='<div class="'.$style.'">
		<ul class="nav">
			<li>
				'.html::image(IMGPATH.'add.png').'
				<ul>
					';
					foreach($params as $param){
						$r.='<li>';
						$r.= html::anchor($param['link'], $param['title']);
						$r.='</li>';
					}
				$r.='</ul>
			</li>
		</ul>
		</div>';
		
		return $r;
	}
	
	
	public static function mediacontainer($content){
		$container=new View('contmedlink/container');
		$container->content=$content;
		return $container;	
	}
	
	public static function filecontainer($content){
		$container=new View('contmedlink/filecontainer');
		$container->content=$content;
		return $container;	
	}
	
	
	public static function commentcontainer($content){
		$container=new View('comment/container');
		$container->content=$content;
		return $container;	
	}
	public static function contentcontainer($content){
		$container=new View('content/container');
		$container->content=$content;
		return $container;	
	}
	
	public static function categorycontainer($content){
		$container=new View('contcategory/container');
		$container->content=$content;
		return $container;	
	}
	
	public static function contentcontainer_defined($content, $addlink, $orderby){
		$pcont=$content;
		echo '<div class="comments">';	
		echo '<div class="header">';		
		echo sigi::addbox($addlink, 'actionbox');
		echo 'Contents';
		echo '</div>';	
		$contmods = ORM::factory('contentmodule')->orderby('title')->find_all();
		$count=0;
		foreach ($pcont->orderby($orderby)->children as $content){
			$content_view=new View('content/single');
			$content_view->content=$content;
			echo $content_view;	
			$count++;
		}
		echo '</div>';
	}
	
	public static function contentcontainer_for_contents($content, $contmodarray=NULL, $orderby="position"){
		$pcont=$content;

		if($contmodarray==NULL){
			$contmodarray=ORM::factory('contentmodule')->find_all()->select_list('id', 'title');
		}
		$addlink=array();
		foreach($contmodarray as $cmid=>$cmtitle){
			$addlink[]=array('title'=>$cmtitle, 'link'=>CONTDIR.'content/form?parent_id='.$pcont->id.'&contmod_id='.$cmid.'&parent_column=parent_id');
		}		
		echo '<div class="containerbox contents">';	
		echo '<div class="header">';		
		echo sigi::addbox($addlink, 'actionbox');
		echo 'Zusätzliche Contents';
		echo '</div>';	
		echo '<div class="container">';
		$contmods = ORM::factory('contentmodule')->orderby('title')->find_all();
		$count=0;
		foreach ($pcont->orderby($orderby)->children as $content){
			$content_view=new View('content/single');
			$content_view->content=$content;
			echo $content_view;	
			$count++;
		}
		echo '</div>';
		echo '</div>';
	}

	
	
}